package de.hdu.myjobapp.dao;

import java.util.List;


import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import de.hdu.myjobapp.model.Keyword;

public class KeywordDao extends HibernateDaoSupport{
	/**
	 * create a new Keyword
	 */	
	public void create(Integer keySort, Integer keyType, String keyName){
		Keyword k = new Keyword();
		k.setKeyName(keyName);
		k.setKeySort(keySort);
		k.setKeyType(keyType);
		save(k);
	}
		
	/**
	 * Saves the new recieved Keyword from Method create with hibernate into database
	 */	
	public Keyword save(Keyword key){
		HibernateTemplate template = getHibernateTemplate();
		template.saveOrUpdate(key);
		return key;
	}

	/**
	 * return all existing Keyword
	 */	
	public List<Keyword> findAll(){
		HibernateTemplate template = getHibernateTemplate();
		return template.loadAll(Keyword.class);
	}

	/**
	 * Return an existing Keyword by naming ID
	 */	
	public Keyword findById(int id){
		HibernateTemplate template = getHibernateTemplate();
		return(Keyword) template.get(Keyword.class, id);
	}


}
